package com.liu.community.controller;/*
 *@Author:Liu Xing-zhi
 *Description:
 *Date:Crated in 13:36 2021/10/11
 */

import com.liu.community.dto.CommentDto;
import com.liu.community.dto.QuestionDto;
import com.liu.community.server.CommentService;
import com.liu.community.server.QuestionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

import java.util.List;

@Controller
public class QuestionController {

    @Autowired
    private QuestionService questionService;
    @Autowired
    private CommentService commentService;
    @GetMapping("/question/{id}")
    public String goQuestion(@PathVariable(name = "id")Integer id, Model model){
        QuestionDto questionDto = questionService.queryQuestionById(id);
        List<QuestionDto> questionDtoRelated = questionService.queryRelated(questionDto);
        List<CommentDto> commentDtoList = commentService.queryCommentByQuestionIdAndType(id);
        //增加阅读数
        questionService.increViewCount(id);
        model.addAttribute("question",questionDto);
        model.addAttribute("comments",commentDtoList);
        model.addAttribute("relatedQuestion",questionDtoRelated);
        return  "question";
    }
}
